﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace AppFabricSample.Data
{

    public class Student
    {
        static SqlConnection con = new SqlConnection("Data Source=DS-D02788816D9E;Initial Catalog=AppFabricSample;Persist Security Info=True;User ID=AppFabric;Password=AppFabric");

        public int RollNo { get; set; }
        public String Name { get; set; }
        public double Marks { get; set; }

        public static Student GetStudentByRollNo(int rollno)
        {
            Student s = null;

            SqlDataAdapter adcom = new SqlDataAdapter("select * from  student where RollNo =" + rollno.ToString() + "", con);
            DataTable dt = new DataTable();
            adcom.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                s = new Student();
                s.RollNo = Convert.ToInt32(dt.Rows[0]["RollNo"]);
                s.Name = dt.Rows[0]["Name"].ToString();
                s.Marks = Convert.ToDouble(dt.Rows[0]["Marks"]);
            }
            dt.Dispose();

            return s;
        }

        public static Student GetStudentByName(string name)
        {
            // Populate the Student
            Student s = null;

            SqlDataAdapter adcom = new SqlDataAdapter("select * from  student where name ='" + name + "'", con);
            DataTable dt = new DataTable();
            adcom.Fill(dt);


            if (dt.Rows.Count > 0)
            {
                s = new Student();
                s.RollNo = Convert.ToInt32(dt.Rows[0]["RollNo"]);
                s.Name = dt.Rows[0]["Name"].ToString();
                s.Marks = Convert.ToDouble(dt.Rows[0]["Marks"]);
            }
            dt.Dispose();

            return s;
        }
    }
}
